{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "756fb0d9-9fa2-412b-b95c-056e4d80365b",
   "metadata": {},
   "source": [
    "# 传送带驱动 demo"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4a62bd6c-b6f8-4349-bcd0-79d962896977",
   "metadata": {},
   "source": [
    "## 初始化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "11863564-0fc5-43f0-9495-5c0069cff7c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "from robodyno import Robot\n",
    "from robodyno.nodes import StepperBoardFactory\n",
    "robot = Robot()\n",
    "device_id = 0x22\n",
    "stepper_board = robot.add_device('stepper', StepperBoardFactory(), device_id, reduction = 10)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b06397c3-a31e-4842-a2c8-20b7bea0c704",
   "metadata": {},
   "source": [
    "## 使能"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "196102e8-ecfc-40af-b377-44a378e5f863",
   "metadata": {},
   "outputs": [],
   "source": [
    "stepper_board.enable()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e2ef2ff7-8531-4a2d-8da2-e45f832beb3d",
   "metadata": {},
   "source": [
    "## 失能"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "ca028c43-9ff0-4d10-8425-a7868171907b",
   "metadata": {},
   "outputs": [],
   "source": [
    "stepper_board.disable()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e254bb14-a387-4aec-83d4-76f318a83bc6",
   "metadata": {},
   "source": [
    "## 转动"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "4a896aca-a08c-4bbe-864d-c5dd8802c03f",
   "metadata": {},
   "outputs": [],
   "source": [
    "stepper_board.set_vel(-1.5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0eeb55c5-2129-4b95-b19b-aaad551e20ca",
   "metadata": {},
   "source": [
    "## 停止"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "44901ab5-9fa9-4a54-b0e2-ac6463376dcd",
   "metadata": {},
   "outputs": [],
   "source": [
    "stepper_board.stop()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "55a44b4a-00e4-4914-bce4-a5b5702a55ad",
   "metadata": {},
   "source": [
    "## 交互"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "16d7b1af-0d7c-4f0f-9e6f-1bb3308ff60b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "9194c9483aa2474c98578370cf6ae237",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(Checkbox(value=False, description='enable'), FloatSlider(value=0.0, description='vel', m…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from ipywidgets import interact\n",
    "@interact(enable = False, vel=(0, 1, 0.01))\n",
    "def demo(enable, vel = 0):\n",
    "    if enable:\n",
    "        stepper_board.enable()\n",
    "    else:\n",
    "        stepper_board.disable()\n",
    "    stepper_board.set_vel(-vel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3b93d140-ed22-4630-a7f2-479df2161bdb",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
